package connect4client.commands;

import messages.InvalidInvitationReplyMessage;
import connect4client.core.GameManager;
import connect4client.core.Invitation;

/**
 * The InvalidInvitationReplyCommand command.
 * 
 * This command will handle InvalidInvitationReply messages.
 */
public class InvalidInvitationReplyCommand extends Command {

	public InvalidInvitationReplyCommand(InvalidInvitationReplyMessage message){
		super(message);
	}

	@Override
	public void execute() {		
		InvalidInvitationReplyMessage message = (InvalidInvitationReplyMessage)this.message;
		
		GameManager gameManager = controller.getGameManager();
		synchronized(gameManager) {	
			Invitation invitation = gameManager.getInvitationByID(message.getReplyId());	
			gameManager.removeInvitation(message.getReplyId());
			guiMediator.invitationTimedOut(invitation.getSender().getLogin(), invitation.getGameName());
		}
	}

}
